package com.ruoyi.blog.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author: user1
 * date: 2021/11/28
 */
@Component
public class MyResourcesConfig {

    /**
     * 上传服务器路径
     */
    @Value("${file.path}")
    private String localFilePath;

    public String  getFullPath(String partPath){
        if(partPath == null || partPath.length() == 0){
            return "";
        }
        int n = 0;
        if(localFilePath.charAt(localFilePath.length() - 1) == '/'){
            n++;
        }
        if(partPath.charAt(0) == '/') n++;
        StringBuilder sb = new StringBuilder();
        if(n == 2){
            sb.append(localFilePath).append(partPath.substring(1));
        }else if(n == 1){
            sb.append(localFilePath).append(partPath);
        }else if(n == 0){
            sb.append(localFilePath).append('/').append(partPath);
        }
        return sb.toString();
    }
}
